const fs=require("fs");
const path=require("path");
const template=require("art-template");

const tempPath={
    //将以当前文件所在文件夹参考的相对路径转换为系统物理真实路径，保证任何位置调用都不会因为路径错误导致错误
    users:path.join(__dirname,'../template/users.html'),
    travel:path.join(__dirname,'../template/travel.html'),
    userList:path.join(__dirname,'../template/userList.html')
};
let user={
    id:123456,
    name:"徐开骋",
    phone:13856987451
};

//请求路径是"/travel"
let arrs=[
    {
        city:"南京",
        travel:["中山陵","玄武湖","夫子庙","老门东"]
    },
    {
        city:"苏州",
        travel:["观前街","山塘街","拙政园","周庄"]
    },
    {
        city:"无锡",
        travel:["鼋头渚","南禅寺","灵山大佛","三国城"]
    }
];


// 访问请求路径是"/list"
let list={
    name:"wbs22062",
    lists:[
        {
            stuId:1001,
            stuName:"花花",
            age:23,
            sex:0
        },
        {
            stuId:1002,
            stuName:"小米",
            age:22,
            sex:1
        },
        {
            stuId:1003,
            stuName:"小红",
            age:25,
            sex:0
        },
        {
            stuId:1004,
            stuName:"小明",
            age:21,
            sex:1
        },
        {
            stuId:1005,
            stuName:"笑笑",
            age:20,
            sex:0
        }
    ]
};




const findUser=function(){

    
    // let p=path.join(__dirname,'../template/users.html');
    // let temp=fs.readFileSync("./template/users.html").toString();
    let temp=fs.readFileSync(tempPath.users).toString();
    temp=temp.replace("{{id}}",user.id);
    temp=temp.replace("{{name}}",user.name);
    temp=temp.replace("{{phone}}",user.phone);
    return temp;
};

const findTravel=function(){
    let temp2=fs.readFileSync(tempPath.travel).toString();//字符串
    let str=template.render(temp2,{"arrs":arrs});
    return str;
};

const findList=function(){
    let temp3=fs.readFileSync(tempPath.userList).toString();//字符串
    let strs=template.render(temp3,list);
    return strs;
};
module.exports={
    findUser,
    findTravel,
    findList
};